﻿
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyWeb.Common;
using MyWeb.Business;
using MyWeb.Data;

namespace MyWeb.Admins
{
    public partial class tblOrder : System.Web.UI.Page
    {
        static bool Insert = false;protected void Page_Load(object sender, EventArgs e){if (!IsPostBack){Session["folder"] = "tblOrder"; BindGrid();}}
private void BindGrid(){grdtblOrder.DataSource = tblOrderService.tblOrder_GetByAll() ;grdtblOrder.DataBind();}
protected void btnThem_Click(object sender, EventArgs e){pnShow.Visible = false;pnUpdate.Visible = true;ControlClass.ResetControlValues(this);Session["upload"] = null;Insert=true;}
protected void btnXoa_Click(object sender, EventArgs e){try{DataGridItem item = default(DataGridItem);for (int i = 0; i < grdtblOrder.Items.Count; i++){item = grdtblOrder.Items[i];if (item.ItemType == ListItemType.AlternatingItem | item.ItemType == ListItemType.Item){if (((CheckBox)item.FindControl("ChkSelect")).Checked){string strId = item.Cells[1].Text;try{tblOrderService.tblOrder_Delete(strId);}catch{}}}}grdtblOrder.CurrentPageIndex = 0;BindGrid();}catch{}}protected void grdtblOrder_ItemCommand(object source, DataGridCommandEventArgs e){Data.tblOrderInfo strCA=new tblOrderInfo();
strCA._oid = e.CommandArgument.ToString();
if (e.CommandName == "Edit") { DataTable dt = tblOrderService.tblOrder_GetById(strCA); txt_uid.Text = dt.Rows[0]["_uid"].ToString(); dll_sid_Update.SelectedValue = dt.Rows[0]["_sid"].ToString(); txt_oid.Text = dt.Rows[0]["_oid"].ToString(); txt_ocreatedate.Text = dt.Rows[0]["_ocreatedate"].ToString(); txt_ostatus.Text = dt.Rows[0]["_ostatus"].ToString(); pnUpdate.Visible = true; pnShow.Visible = false; } else { tblOrderService.tblOrder_Delete(strCA._oid); BindGrid(); }
}protected void lblBack_Click(object sender, EventArgs e) { pnUpdate.Visible = false; pnShow.Visible = true; Insert = false; }
protected void lblUpdate_Click(object sender, EventArgs e)
{
    string image = Session["upload"] == null ? "" : Session["upload"].ToString();
    #region[TestInput]
    if (txt_uid.Text.Trim().Equals("")) { WebMsgBox.Show("_uid không thể trống !"); txt_uid.Focus(); return; } if (dll_sid_Update.SelectedValue.Trim().Equals("")) { WebMsgBox.Show("_sid không thể trống !"); dll_sid_Update.Focus(); return; } if (txt_oid.Text.Trim().Equals("")) { WebMsgBox.Show("_oid không thể trống !"); txt_oid.Focus(); return; } if (txt_ocreatedate.Text.Trim().Equals("")) { WebMsgBox.Show("_ocreatedate không thể trống !"); txt_ocreatedate.Focus(); return; } if (txt_ostatus.Text.Trim().Equals("")) { WebMsgBox.Show("_ostatus không thể trống !"); txt_ostatus.Focus(); return; }
#endregion
    Data.tblOrderInfo obj = new Data.tblOrderInfo(); obj._uid = txt_uid.Text; obj._sid = dll_sid_Update.SelectedValue; obj._oid = txt_oid.Text; obj._ocreatedate = txt_ocreatedate.Text; obj._ostatus = txt_ostatus.Text; if (Insert == true) { tblOrderService.tblOrder_Insert(obj); } else { tblOrderService.tblOrder_Update(obj); } BindGrid(); pnShow.Visible = true; pnUpdate.Visible = false; Insert = false;
}protected void grdtblOrder_PageIndexChanged(object source, DataGridPageChangedEventArgs e){grdtblOrder.CurrentPageIndex = e.NewPageIndex;BindGrid();}private void ShowDll()
{var dt = new DataTable();
dt = tblImgSizeService.tblImgSize_GetByAll();
dll_sid.DataSource = dt; dll_sid.DataTextField = ""; dll_sid.DataValueField = ""; dll_sid.DataBind(); dll_sid_Update.DataSource = dt; dll_sid_Update.DataTextField = ""; dll_sid_Update.DataValueField = ""; dll_sid_Update.DataBind();
}protected void btnshow_Click(object sender, EventArgs e) { grdtblOrder.DataSource = tblOrderService.tblOrder_GetBy_sid(dll_sid.SelectedValue); grdtblOrder.DataBind(); }
protected void grdtblOrder_ItemDataBound(object sender, DataGridItemEventArgs e)
{
ListItemType itemType = e.Item.ItemType;if ((itemType != ListItemType.Footer) && (itemType != ListItemType.Separator)){if (itemType == ListItemType.Header){object checkBox = e.Item.FindControl("chkSelectAll");if ((checkBox != null)){((CheckBox)checkBox).Attributes.Add("onClick", "Javascript:chkSelectAll_OnClick(this)");
}
}else{
string tableRowId = grdtblOrder.ClientID + "_row" + e.Item.ItemIndex.ToString();
e.Item.Attributes.Add("id", tableRowId);
object checkBox = e.Item.FindControl("chkSelect");
if ((checkBox != null))
{e.Item.Attributes.Add("onMouseMove", "Javascript:chkSelect_OnMouseMove(this)");
e.Item.Attributes.Add("onMouseOut", "Javascript:chkSelect_OnMouseOut(this," + e.Item.ItemIndex + ")");((CheckBox)checkBox).Attributes.Add("onClick", "Javascript:chkSelect_OnClick(this," + e.Item.ItemIndex + ")");}}}}
}
}